$(function () {
    $.prototype.serializeObject = function () {
        let a, o, h, i, e;
        a = this.serializeArray();
        o = {};
        h = o.hasOwnProperty;
        for (i = 0; i < a.length; i++) {
            e = a[i];
            if (!h.call(o, e.name)) {
                o[e.name] = e.value;
            }
        }
        return o;
    }
    // 提交表单。
    $("#user-form, #news-form, #model-form").submit(function () {
        let $form = $(this);
        let data = $form.serializeObject();
        if (data.user_name === "" || data.user_name === null || data.user_name === undefined) {
            alert("请输入姓名");
            return false;
        }
        if (data.phone_number === "" || data.phone_number === null || data.phone_number === undefined) {
            alert("请输入手机号");
            return false;
        }
        if (data.city === "" || data.city === null || data.city === undefined) {
            alert("请输入城市");
            return false;
        }
        if (data.major === "" || data.major === null || data.major === undefined) {
            alert("请输入专业");
            return false;
        }
        $.ajax({
            url: $form.attr("action"),
            type: $form.attr("method"),
            data: data,
            dataType: "JSON",
            success: function (r) {
                $form[0].reset();
                alert(r.msg);
            }
        });
        return false;
    });
})
